   //
//  AppDelegate.swift
//  小陈微博Swift用纯代码创建
//
//  Created by 小陈 on 16/2/26.
//  Copyright © 2016年 小陈. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        setupUITabBarItemCorlor()
        
        // 创建window
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
         // 指定 主控制器
        let TabBar = XCMainViewController()
                window?.rootViewController = TabBar
        // 显示欢迎界面
//         let welcomVC = XCWelcomViewController()
  
        // 显示新特性界面
//        let NewFeatureVC = XCNewFeatureController()
        
        
        // 判断用户是否登录
//        XCUSerAccountViewModel.sharedInstance.isUserLogin
        
//        window?.rootViewController = XCWelcomViewController()
        
        
        

        
        
        
        
//        window?.rootViewController = defaultController()
        //显示跟控制器
        window?.makeKeyAndVisible()
        
        
        return true
    }
    
    /// 设置默认的显示界面
    func defaultController () -> UIViewController {
        
        if !XCUSerAccountViewModel.sharedInstance.isUserLogin {
            return XCMainViewController()
        }
        return isNewFeature() ? XCNewFeatureController() : XCWelcomViewController()
        
    }
    
    func SwicthRootViewController(isMain:Bool)  {
       window?.rootViewController = isMain ? XCMainViewController() : XCWelcomViewController()
    }
    
    
    func isNewFeature() -> Bool{
        //  获取当前的版本
        let saveVisionValueKey  = "saveVisionValueKey"
        let newVision = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String
        // 获取上一个的版本
        
        let oldVision = NSUserDefaults.standardUserDefaults().stringForKey(saveVisionValueKey)
        // 对比
        let isNewVision = newVision != oldVision
        
        // 是否显示新特性界面  将新版本保存到沙盒中
        if isNewVision {
            NSUserDefaults.standardUserDefaults().setValue(newVision, forKeyPath: saveVisionValueKey)
            NSUserDefaults.standardUserDefaults().synchronize()
            
        }
        return isNewVision
        
    }
    
    
    /// 设置导航条上按钮的文本颜色
    func setupUITabBarItemCorlor(){
    
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        
        // 设置tabBar 上的颜色
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

